package cn.da.shuai.cool.system.service.domain;

import cn.da.shuai.cool.system.model.enums.user.UserStatusType;
import cn.da.shuai.cool.system.model.entity.user.CoolUser;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

public class CoolUserDetails implements UserDetails {

    @Getter
    private final CoolUser coolUser;
    private final Collection<? extends GrantedAuthority> authorities;

    public CoolUserDetails(CoolUser coolUser, Collection<? extends GrantedAuthority> authorities) {
        this.coolUser = coolUser;
        this.authorities = authorities;
    }

    public CoolUserDetails(CoolUser coolUser) {
        this(coolUser, List.of()); // Default constructor with empty authorities
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return coolUser.getPassword();
    }

    @Override
    public String getUsername() {
        return coolUser.getUsername();
    }

    @Override
    public boolean isEnabled() {
        return UserStatusType.NORMAL.equals(coolUser.getStatus());
    }

}
